<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><title>Hexo浏览器定向推送文章更新 | CC的部落格</title><meta name="author" content="CC康纳百川"><meta name="copyright" content="CC康纳百川"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="ffffff"><article data-clarity-region="article"></article><meta name="description" content="这一次，CC的部落格可以根据读者订阅主题定向推送了，并且实现了NPM插件化"><meta property="og:type" content="article"><meta property="og:title" content="Hexo浏览器定向推送文章更新"><meta property="og:url" content="https://blog.ccknbc.cc/posts/hexo-webpushr-notification/"><meta property="og:site_name" content="CC的部落格"><meta property="og:description" content="这一次，CC的部落格可以根据读者订阅主题定向推送了，并且实现了NPM插件化"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/d2a947d48815ed24936a919873b97841_w1366_h768_s31.png"><meta property="article:published_time" content="2022-10-04T16:00:00.000Z"><meta property="article:modified_time" content="2023-08-29T05:05:00.000Z"><meta property="article:author" content="CC康纳百川"><meta property="article:tag" content="博客"><meta property="article:tag" content="工具"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/d2a947d48815ed24936a919873b97841_w1366_h768_s31.png"><link rel="shortcut icon" href="/favicon.ico"><link rel="canonical" href="https://blog.ccknbc.cc/posts/hexo-webpushr-notification/"><link rel="preconnect" href="https://jsd.cdn.zzko.cn"><link rel="preconnect" href="//static.cloudflareinsights.com"><link rel="preconnect" href="//www.clarity.ms"><link rel="preconnect" href="//busuanzi.ibruce.info"><link rel="preconnect" href="https://97MUPN4DMC-dsn.algolia.net" crossorigin=""><meta name="google-site-verification" content="tUkgeN6Ih2ArWtjw47oNSSl4Af2_MWjiKLrzZptUCdM"><meta name="msvalidate.01" content="71ADBCC80D679CEA8080BAFDCD54E368"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://jsd.cdn.zzko.cn/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://jsd.cdn.zzko.cn/npm/node-snackbar/dist/snackbar.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://jsd.cdn.zzko.cn/npm/@fancyapps/ui/dist/fancybox/fancybox.css" media="print" onload='this.media="all"'><script>(()=>{const t={set:(e,t,a)=>{var o;0!==a&&(o=Date.now(),localStorage.setItem(e,JSON.stringify({value:t,expiry:o+864e5*a})))},get:e=>{var t=localStorage.getItem(e);if(t){t=JSON.parse(t);if(!(Date.now()>t.expiry))return t.value;localStorage.removeItem(e)}}},a=(window.btf={saveToLocal:t,getScript:(o,n={})=>new Promise((t,e)=>{const a=document.createElement("script");a.src=o,a.async=!0,a.onerror=e,a.onload=a.onreadystatechange=function(){var e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(a.onload=a.onreadystatechange=null,t())},Object.keys(n).forEach(e=>{a.setAttribute(e,n[e])}),document.head.appendChild(a)}),getCSS:(o,n=!1)=>new Promise((t,e)=>{const a=document.createElement("link");a.rel="stylesheet",a.href=o,n&&(a.id=n),a.onerror=e,a.onload=a.onreadystatechange=function(){var e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(a.onload=a.onreadystatechange=null,t())},document.head.appendChild(a)}),addGlobalFn:(e,t,a=!1,o=window)=>{var n=o.globalFn||{},d=n[e]||{};a&&d[a]||(d[a=a||Object.keys(d).length]=t,n[e]=d,o.globalFn=n)}},()=>{document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#0d0d0d")}),o=()=>{document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","ffffff")};btf.activateDarkMode=a,btf.activateLightMode=o;var e=t.get("theme"),n=window.matchMedia("(prefers-color-scheme: dark)").matches,d=window.matchMedia("(prefers-color-scheme: light)").matches,r=window.matchMedia("(prefers-color-scheme: no-preference)").matches,c=!n&&!d&&!r,n=(void 0===e?(d?o():n?a():(r||c)&&((d=(new Date).getHours())<=6||18<=d?a:o)(),window.matchMedia("(prefers-color-scheme: dark)").addListener(e=>{void 0===t.get("theme")&&(e.matches?a:o)()})):("light"===e?o:a)(),t.get("aside-status"));void 0!==n&&("hide"===n?document.documentElement.classList.add("hide-aside"):document.documentElement.classList.remove("hide-aside"));/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")})()</script><script defer data-pjax="data-pjax" src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon="{&quot;token&quot;: &quot;35785b58f09f472ebfd7a2854973e6b8&quot;}"></script><script>!function(t,e,n,a,c,r){t[n]=t[n]||function(){(t[n].q=t[n].q||[]).push(arguments)},(c=e.createElement(a)).async=1,c.src="https://www.clarity.ms/tag/an4gdfm6a9",(r=e.getElementsByTagName(a)[0]).parentNode.insertBefore(c,r)}(window,document,"clarity","script")</script><script>const GLOBAL_CONFIG={postHeadAiDescription:{enable:!0,gptName:"CC",mode:"tianli",switchBtn:!0,btnLink:"https://tianli-blog.club/tianligpt/",randomNum:3,basicWordCount:1e3,key:"VCtoijR43E2uiVWkrZiC",Referer:"https://blog.ccknbc.cc/"},root:"/",algolia:void 0,localSearch:void 0,translate:{defaultEncoding:2,translateDelay:0,msgToTraditionalChinese:"繁",msgToSimplifiedChinese:"简"},noticeOutdate:{limitDay:15,position:"top",messagePrev:"本文最后一次更新为",messageNext:"天前，文章中的某些内容可能已过时！"},highlight:{plugin:"highlight.js",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:!1,highlightFullpage:!0,highlightMacStyle:!0},copy:{success:"复制成功",error:"复制错误",noSupport:"浏览器不支持"},relativeDate:{homepage:!1,post:!1},runtime:"天",dateSuffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:{limitCount:100,languages:{author:"作者: CC康纳百川",link:"链接: ",source:"来源: CC的部落格",info:"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},lightbox:"fancybox",Snackbar:{chs_to_cht:"你已切换为繁体中文",cht_to_chs:"你已切换为简体中文",day_to_night:"你已切换为深色模式",night_to_day:"你已切换为浅色模式",bgLight:"#49b1f5",bgDark:"#1f1f1f",position:"top-center"},infinitegrid:{js:"https://jsd.cdn.zzko.cn/npm/@egjs/infinitegrid/dist/infinitegrid.min.js",buttonText:"加载更多"},isPhotoFigcaption:!1,islazyload:!0,isAnchor:!1,percent:{toc:!0,rightside:!0},autoDarkmode:!0}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={postAI:"这一次，CC的部落格可以根据读者订阅主题定向推送了，并且实现了NPM插件化",pageFillDescription:"安装, 自定义修改, 使用, 额外配置, 自定义, 工作原理, 推送效果, 后续计划查看本文语雀版本首发自动同步更新至的部落格两年前我刚开始使用的时候写了一篇文章简单浏览器更新推送的实现最近登录控制台发现其支持按话题指定推送了而原来的插件一直没有更新且对个人的写作习惯不是很友好所以对原插件进行了修改并发布到了欢迎大家前往订阅页面选择合适的订阅方式关于邮件订阅现已支持分类订阅安装推荐使用以插件形式安装自定义修改当然你也可以自定义修改文件后再安装相关需要依赖然后将文件放到目录下即可正常运行本人亦是如此对于以上版本您只需要在所在目录安装即可这样测试相较于安装更方便以及欢迎使用在你的根目录配置文件中添加如下内容可按需配置建议前往查看最新配置出于安全考虑建议将上述两个重要参数添加至系统全局环境变量并删除或注释掉此处配置否则可在网页端向访问者或订阅用户发送推送例如环境变量配置参数名不变密钥名自定义可参考如下如果您的仓库私有则无需担心此问题必须为以及图片默认为代表即自动隐藏默认为即只要最新文章更改了更新时间即推送新文章改为即文章第一次发布时间延时推送考虑到缓存更新默认定时为在分钟后推送单位为分钟最短延时为分钟设置则会立即推送推送过期时长默认值为天格式如下代表分钟代表小时代表天默认为文章封面属性为主题友好选项如果您没有定义默认封面或此属性请在这里设置默认如果你需要额外自定义按钮可按照如下格式阅读全文当未配置时默认值为前往查看当未配置时默认值为最新文章链接订阅页面当未定义时也默认保留了一个前往查看按钮除非设置为当设为则不显示额外的按钮因为隐藏按钮即为当前文章链接以下配置为按订阅主题推送给不同订阅用户请按照数组形式一一对应具体位置请看使用文档工作博客工具生活音乐学习可选配置默认为即根据不同主题推送细分同时配置上述选项例如即推送至所有用户针对本地测试建议只推送给单个用户即自己同时设置下方的值您也可以将设置为对应的同样也可以实现推送至所有用户单个用户可在控制台查看此外在文章处可覆盖和配置针对需要特别提醒文章可以设置不自动隐藏及过期时间延长等操作以及可指定参数例如定时推送当文章头设置时可关闭本篇文章推送此参数主要防止久远文章更改更新时间后自动推送前往控制台获取如下参数注册的时候可能会遇到一点困难中国大陆用户需要科学上网来加载验证服务关于注册及一些具体内容可以看之前的文章简单浏览器更新推送的实现依次点击即可看到你的及依次点击可以看到如下代码最后一行就是你的注意因权限问题本地测试时可能不会显示弹窗但如果你配置了小铃铛小铃铛会显示额外配置因官方脚本注册后我们无法注册自己的脚本但官方提供了配置方便我们使用的缓存拦截请求等功能首先在配置项中添加配置开启自行注册默认用户不用添加或者设为另外你还需要在你的脚本文件例如中引入完成这些你就可以自行注册你的脚本了如果你需要了解如何编写或注册脚本可以参考以下文章或项目自定义个人建议将控制台右上角小铃铛里全部配置一遍以获得更好的效果你需要自定义一些参数才可以使用根据不同主题按照订阅者订阅话题推送功能目前根据个人需求是这个设置默认行为为当未匹配到对应分类时不推送文章而不是向所有用户推送文章当然你也可以配置目标为所有用户在控制台点击向下滑动打开小铃铛样式无此选项因此推荐您使用前两种样式并新增几个主题对应你想推送的文章分类即可然后点击即可获取对应的关系依次填入配置项即可工作原理当你运行插件会在目录生成这样一个文件包含了一些你想推送的新文章相关信息示例格式如下浏览器定向推送文章更新这一次的部落格可以根据读者订阅主题定向推送了并且实现了插件化博客而他的来源就是我们在文章开头自定义的那些属性而本插件针对主题做了针对性修改您也可以在您的模板文件目录下修改文章模板文件主要针对性参数如下对应配置项中定时推送时间对应配置项中是否自动隐藏对应配置项中过期时间文章分类对应配置项中即文章描述对应配置项中默认选取文章封面如果你的主题不是采用默认的参数记得补充因为这是判断最新文章的依据如果你习惯了使用截断的方式也无需配置继续使用示例如下注意使用浏览器通知推送服务器推送技术开发是怎么工作的个人博客为什么要使用它如何使用它当执行命令时插件会比较在线版本和本地版本中最新文章更新时间是否一致如果不同则插件将推送最新文章更新通知默认为十分钟后推送注意如果您是第一次使用本地测试应该看到无文章更新或为首次推送更新这是正常现象因为此时你的网站还没有这个文件后续有更新时将正常推送你可以先推送一次再修改更新时间测试一次当然建议测试目标选择自己即选项配置当然如果您在使用过程中有什么问题或遇到了也欢迎随时在评论区或反馈当然因为本人是菜鸡所以有大佬最好了推送效果因为我是通知自动隐藏后才截图所以大致效果如下所示后续计划兼容自定义的功能因为优先注册的原因只能有一个注册无法注册自己编写脚本支持参数更多的可自定义启用或关闭例如不延时立即发送不显示按钮因为默认就是跳转到文章等目前的判断逻辑虽然可以根据更新时间来判断但如果很久之前的文章翻新只要更新时间最新也会触发推送主要针对方式还没想到好的解决办法目前就是确认需要推送才更改更新时间咯优化代码减少代码量",title:"Hexo浏览器定向推送文章更新",isPost:!0,isHome:!1,isHighlightShrink:!1,isToc:!0,postUpdate:"2023-08-29 13:05:00"}</script><script>"serviceWorker"in navigator&&(navigator.serviceWorker.register("/sw.js",{scope:"/"}).then(r=>{r.onupdatefound=()=>{const e=r.installing;e.onstatechange=()=>{"installed"===e.state&&(navigator.serviceWorker.controller?(void 0!==GLOBAL_CONFIG.Snackbar&&btf.snackbarShow("已刷新缓存，更新为最新内容"),navigator.serviceWorker.controller.postMessage({type:"skipWaiting"})):console.log("第一次注册Service Worker"))}}}),navigator.serviceWorker.addEventListener("message",e=>{e.data&&"refresh"===e.data.type&&(console.log("收到刷新页面请求，开始刷新页面"),window.location.reload())}))</script><link rel="stylesheet" href="https://jsd.cdn.zzko.cn/npm/hexo-butterfly-tag-plugins-plus/lib/assets/font-awesome-animation.min.css" media="defer" onload='this.media="all"'><link rel="stylesheet" href="https://jsd.cdn.zzko.cn/npm/hexo-butterfly-tag-plugins-plus/lib/tag_plugins.css" media="defer" onload='this.media="all"'><meta name="generator" content="Hexo 7.2.0"><link rel="alternate" href="/atom.xml" title="CC的部落格" type="application/atom+xml"><link rel="alternate" href="/rss.xml" title="CC的部落格" type="application/rss+xml"></head><body><script>window.paceOptions={restartOnPushState:!1},btf.addGlobalFn("pjaxSend",()=>{Pace.restart()},"pace_restart")</script><link rel="stylesheet" href="https://jsd.cdn.zzko.cn/gh/CodeByZach/pace/themes/green/pace-theme-flash.css"><script src="https://jsd.cdn.zzko.cn/npm/pace-js/pace.min.js"></script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://jsd.cdn.zzko.cn/gh/ccknbc-backup/cdn/logo/logo.png" onerror='onerror=null,src="https://jsd.cdn.zzko.cn/npm/hexo-theme-anzhiyu/source/img/404.jpg"' alt="avatar"></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">38</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">7</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div><hr class="custom-hr"><div class="menus_items"><div class="menus_item"><span class="site-page group"><i class="fa-fw fa-solid fa-book-reader"></i><span> 文章</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa-solid fa-box-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa-solid fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa-solid fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><span class="site-page group"><i class="fa-fw fa-solid fa-cubes"></i><span> 社交</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/blogroll/"><i class="fa-fw fa-solid fa-link"></i><span> 友链</span></a></li><li><a class="site-page child" href="/moments/"><i class="fa-fw fa-solid fa-blog"></i><span> 友圈</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa-solid fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/essay/"><i class="fa-fw fa-solid fa-comment-alt"></i><span> 短文</span></a></li></ul></div><div class="menus_item"><span class="site-page group"><i class="fa-fw fa-solid fa-desktop"></i><span> 关于</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/sub/"><i class="fa-fw fa-solid fa-bell"></i><span> 订阅</span></a></li><li><a class="site-page child" href="/about/"><i class="fa-fw fa-solid fa-list-check"></i><span> 本站</span></a></li><li><a class="site-page child" href="/privacy-policy/"><i class="fa-fw fa-solid fa-user-secret"></i><span> 隐私</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://cc.instatus.com"><i class="fa-fw fa-solid fa-server"></i><span> 状态</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image:url(https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/d2a947d48815ed24936a919873b97841_w1366_h768_s31.png)"><nav id="nav"><span id="blog-info"><a href="/" title="CC的部落格"><span class="site-name">CC的部落格</span></a></span><div id="menus"><div id="search-button"><span class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></span></div><div class="menus_items"><div class="menus_item"><span class="site-page group"><i class="fa-fw fa-solid fa-book-reader"></i><span> 文章</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa-solid fa-box-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa-solid fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa-solid fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><span class="site-page group"><i class="fa-fw fa-solid fa-cubes"></i><span> 社交</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/blogroll/"><i class="fa-fw fa-solid fa-link"></i><span> 友链</span></a></li><li><a class="site-page child" href="/moments/"><i class="fa-fw fa-solid fa-blog"></i><span> 友圈</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa-solid fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/essay/"><i class="fa-fw fa-solid fa-comment-alt"></i><span> 短文</span></a></li></ul></div><div class="menus_item"><span class="site-page group"><i class="fa-fw fa-solid fa-desktop"></i><span> 关于</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/sub/"><i class="fa-fw fa-solid fa-bell"></i><span> 订阅</span></a></li><li><a class="site-page child" href="/about/"><i class="fa-fw fa-solid fa-list-check"></i><span> 本站</span></a></li><li><a class="site-page child" href="/privacy-policy/"><i class="fa-fw fa-solid fa-user-secret"></i><span> 隐私</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://cc.instatus.com"><i class="fa-fw fa-solid fa-server"></i><span> 状态</span></a></li></ul></div></div><div id="toggle-menu"><span class="site-page"><i class="fas fa-bars fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">Hexo浏览器定向推送文章更新</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-10-04T16:00:00.000Z" title="发表于 2022-10-05 00:00:00">2022-10-05</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-08-29T05:05:00.000Z" title="更新于 2023-08-29 13:05:00">2023-08-29</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%8D%9A%E5%AE%A2/">博客</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.6k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>9分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" data-flag-title="Hexo浏览器定向推送文章更新"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><div class="post-ai-description"><div class="ai-title"><i class="fa-solid fa-newspaper"></i><div class="ai-title-text">AI-摘要</div><div id="ai-Toggle" title="CC/Tianli 模式切换">切换</div><i class="fa-solid fa-podcast" title="Tianli 模式下朗读摘要"></i><i class="fa-solid fa-arrow-rotate-right" title="Tianli 模式下刷新摘要"></i><div id="ai-tag">Tianli GPT</div></div><div class="ai-explanation">AI初始化中...</div><div class="ai-btn-box"><div class="ai-btn-item">介绍自己 🙈</div><div class="ai-btn-item">生成摘要 👋</div><div class="ai-btn-item">相关推荐 📖</div><div class="ai-btn-item">前往主页 🏠</div><div class="ai-btn-item" id="go-tianli-blog">前往爱发电购买</div></div><script data-pjax src="/"></script></div><article class="post-content" id="article-container"><p>查看本文<a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.yuque.com/ccknbc/blog/37/"><strong>语雀</strong></a>版本【首发】，自动同步更新至<a href="https://blog.ccknbc.cc/posts/hexo-webpushr-notification/"><strong>CC 的部落格</strong></a>！</p><p>两年前，我刚开始使用<code>Hexo</code>的时候，写了一篇文章<a href="https://blog.ccknbc.cc/posts/implementation-of-simple-browser-update-push/">简单浏览器更新推送的实现</a>，最近登录<a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.webpushr.com/">webpushr</a>控制台，发现其支持按话题<code>topic</code>指定推送了，而原来的插件一直没有更新，且对个人的写作习惯不是很友好，所以对原插件进行了修改，并发布到了<code>NPM</code></p><p>欢迎大家前往<a href="/sub">订阅页面</a>选择合适的订阅方式，关于邮件订阅，现已支持分类订阅</p><h2 id="安装">安装<a class="fa-solid fa-hashtag" href="#安装"></a></h2><p>推荐使用 <code>npm</code> 以插件形式安装</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i hexo-webpushr-notification</span><br></pre></td></tr></table></figure><h3 id="自定义修改">自定义修改<a class="fa-solid fa-hashtag" href="#自定义修改"></a></h3><p>当然你也可以自定义修改<a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/Rock-Candy-Tea/hexo-webpushr-notification/blob/main/webpushr.js">webpushr.js</a>文件后，再安装相关需要依赖，然后将文件放到<code>Hexo/scripts/</code>目录下即可正常运行，CC 本人亦是如此对于 0.2.0 以上版本，您只需要在 Hexo 所在目录安装 axios 即可，这样测试相较于安装 GitHub 更方便（以及欢迎 PR ）</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i axios</span><br></pre></td></tr></table></figure><h2 id="使用">使用<a class="fa-solid fa-hashtag" href="#使用"></a></h2><p>在你的 Hexo 根目录配置文件 <code>_config.yml</code>中添加如下内容，可按需配置，建议前往 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/Rock-Candy-Tea/hexo-webpushr-notification#readme">README</a> 查看最新配置</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">webpushr:</span></span><br><span class="line">  <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line">  <span class="attr">webpushrKey:</span> <span class="string">&quot;webpushrKey&quot;</span></span><br><span class="line">  <span class="attr">webpushrAuthToken:</span> <span class="string">&quot;webpushrAuthToken&quot;</span></span><br><span class="line">  <span class="comment"># 出于安全考虑，建议将上述两个重要参数添加至系统全局环境变量，并删除或注释掉此处配置</span></span><br><span class="line">  <span class="comment"># 否则可在网页端向访问者或订阅用户发送推送 https://www.webpushr.com/api-playground</span></span><br><span class="line">  <span class="comment"># 例如GitHub Actions环境变量配置，参数名不变，密钥名自定义，可参考如下</span></span><br><span class="line">  <span class="comment"># env:</span></span><br><span class="line">  <span class="comment">#     webpushrKey: $&#123;&#123; secrets.WEBPUSHR_KEY &#125;&#125;</span></span><br><span class="line">  <span class="comment">#     webpushrAuthToken: $&#123;&#123; secrets.WEBPUSHR_AUTH_TOKEN &#125;&#125;</span></span><br><span class="line">  <span class="comment"># 如果您的仓库私有，则无需担心此问题</span></span><br><span class="line"></span><br><span class="line">  <span class="attr">trackingCode:</span> <span class="string">&quot;trackingCode&quot;</span></span><br><span class="line">  <span class="attr">icon:</span> <span class="string">&quot;https://.../192.png&quot;</span> <span class="comment"># 必须为 HTTPS 以及 192*192 png图片</span></span><br><span class="line">  <span class="comment"># auto_hide: false # 默认为 1，代表true，即自动隐藏</span></span><br><span class="line">  <span class="comment"># sort: &quot;date&quot; # 默认为updated，即只要最新文章更改了更新时间即推送新文章，改为date即文章第一次发布时间</span></span><br><span class="line">  <span class="comment"># delay: &quot;0&quot; # 延时推送，考虑到CDN缓存更新，默认定时为在 hexo d 10分钟后推送，单位为分钟（最短延时为5分钟，设置 0 则会立即推送）</span></span><br><span class="line">  <span class="comment"># expire: &quot;15d&quot; # 推送过期时长，默认值为7天，格式如下：&#x27;5m&#x27;代表5分钟,&#x27;5h&#x27;代表5小时, &#x27;5d&#x27;代表5天.</span></span><br><span class="line">  <span class="comment"># image: # 默认为文章封面，Front-matter 属性为&#x27;cover&#x27;(butterfly主题友好选项)，如果您没有定义默认封面或此属性，请在这里设置默认image</span></span><br><span class="line">  <span class="attr">action_buttons:</span> <span class="comment"># 如果你需要额外自定义按钮 可按照如下格式：</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">title:</span> <span class="string">阅读全文</span> <span class="comment"># 当 title 未配置时 默认值为 “前往查看”</span></span><br><span class="line">      <span class="comment"># url:  # 当 url 未配置时 默认值为 最新文章链接</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">title:</span> <span class="string">订阅页面</span></span><br><span class="line">      <span class="attr">url:</span> <span class="string">https://blog.ccknbc.cc/sub/</span></span><br><span class="line">    <span class="comment"># 当 action_buttons 未定义时也默认保留了一个“前往查看”按钮，除非设置为 false</span></span><br><span class="line">    <span class="comment"># action_buttons: false # 当设为 false 则不显示额外的按钮，因为隐藏按钮即为当前文章链接</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># 以下配置为按订阅主题推送给不同订阅用户，请按照数组形式，一一对应，具体位置请看使用文档</span></span><br><span class="line">  <span class="attr">categories:</span> [<span class="string">工作</span>, <span class="string">博客</span>, <span class="string">工具</span>, <span class="string">生活</span>, <span class="string">音乐</span>, <span class="string">学习</span>]</span><br><span class="line">  <span class="attr">segment:</span> [<span class="string">&quot;484223&quot;</span>, <span class="string">&quot;484224&quot;</span>, <span class="string">&quot;484225&quot;</span>, <span class="string">&quot;484226&quot;</span>, <span class="string">&quot;484227&quot;</span>, <span class="string">&quot;484229&quot;</span>]</span><br><span class="line">  <span class="attr">endpoint:</span> <span class="string">segment</span> <span class="comment"># 可选配置 all / segment / sid</span></span><br><span class="line">  <span class="comment"># 默认为 segment，即根据不同主题推送细分，同时配置上述选项</span></span><br><span class="line">  <span class="comment"># 例如 all，即推送至所有用户；针对本地测试，建议只推送给单个用户即自己，同时设置下方的 sid 值</span></span><br><span class="line">  <span class="comment"># 您也可以将segment 设置为 all-users 对应的ID，同样也可以实现推送至所有用户</span></span><br><span class="line">  <span class="attr">sid:</span> <span class="string">&quot;119810055&quot;</span> <span class="comment"># 单个用户ID 可在控制台查看 https://app.webpushr.com/subscribers</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">  <span class="comment"># 此外，在文章 Front-Matter 处</span></span><br><span class="line">  <span class="comment"># 可覆盖 auto_hide 和 expire 配置，针对需要特别提醒文章可以设置不自动隐藏及过期时间延长等操作</span></span><br><span class="line">  <span class="comment"># 以及可指定schedule参数（例如：schedule: 2022-10-01 00:00:00），定时推送</span></span><br><span class="line">  <span class="comment"># 当文章头设置 webpushr: false 时，可关闭本篇文章推送，此参数主要防止久远文章更改更新时间后自动推送</span></span><br></pre></td></tr></table></figure><ol><li>前往 webpushr 控制台获取如下参数，注册的时候可能会遇到一点困难，中国大陆用户需要科学上网来加载验证服务）</li><li>关于注册及一些具体内容，可以看之前的文章 <a href="https://blog.ccknbc.cc/posts/implementation-of-simple-browser-update-push/">简单浏览器更新推送的实现</a></li><li>依次点击 <code>Integration</code> &gt; <code>REST API Keys</code>，即可看到你的<code>webpushrKey</code> 及 <code>webpushrAuthToken</code></li><li>依次点击 <code>Setup</code> &gt; <code>TrackingCode</code>，可以看到如下代码</li></ol><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- start webpushr tracking code --&gt;</span><br><span class="line">  <span class="language-xml"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript">(<span class="keyword">function</span>(<span class="params">w,d, s, id</span>) &#123;<span class="keyword">if</span>(<span class="title function_">typeof</span>(w.<span class="property">webpushr</span>)!==<span class="string">&#x27;undefined&#x27;</span>) <span class="keyword">return</span>;w.<span class="property">webpushr</span>=w.<span class="property">webpushr</span>||<span class="keyword">function</span>(<span class="params"></span>)&#123;(w.<span class="property">webpushr</span>.<span class="property">q</span>=w.<span class="property">webpushr</span>.<span class="property">q</span>||[]).<span class="title function_">push</span>(<span class="variable language_">arguments</span>)&#125;;<span class="keyword">var</span> js, fjs = d.<span class="title function_">getElementsByTagName</span>(s)[<span class="number">0</span>];js = d.<span class="title function_">createElement</span>(s); js.<span class="property">id</span> = id;js.<span class="property">async</span>=<span class="number">1</span>;js.<span class="property">src</span> = <span class="string">&quot;https://cdn.webpushr.com/app.min.js&quot;</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">                                 fjs.<span class="property">parentNode</span>.<span class="title function_">appendChild</span>(js);&#125;(<span class="variable language_">window</span>,<span class="variable language_">document</span>, <span class="string">&#x27;script&#x27;</span>, <span class="string">&#x27;webpushr-jssdk&#x27;</span>));</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="title function_">webpushr</span>(<span class="string">&#x27;setup&#x27;</span>,&#123;<span class="string">&#x27;key&#x27;</span>:<span class="string">&#x27;BKOlpbdgvBCWXqXI6PtsUzobY7TLV9gwJU8bzMktrwfrSERg_xnLvbjpdw8x2GmFmi1ZcLTz0ni6OnX5MAwoM58&#x27;</span> &#125;);</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br><span class="line">  &lt;!-- end webpushr tracking code --&gt;</span><br></pre></td></tr></table></figure><p>最后一行<code>BKOlpbdgvBCWXqXI6PtsUzobY7TLV9gwJU8bzMktrwfrSERg_xnLvbjpdw8x2GmFmi1ZcLTz0ni6OnX5MAwoM58</code> 就是你的 <code>trackingCode</code></p><p><strong>注意</strong>：因权限问题，本地测试时(<code>hexo s</code>)可能不会显示弹窗，但如果你配置了小铃铛，小铃铛会显示</p><h2 id="额外配置">额外配置<a class="fa-solid fa-hashtag" href="#额外配置"></a></h2><p>因官方 sw 脚本注册后，我们无法注册自己的 sw 脚本，但官方提供了配置，方便我们使用 sw 的缓存，拦截请求等功能</p><p>首先在配置项中添加 <code>sw_self: true</code>配置，开启自行注册 sw（默认用户不用添加或者设为 <code>false</code>）</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">webpushr:</span></span><br><span class="line">  <span class="attr">sw_self:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure><p>另外，你还需要在你的脚本文件（例如<code>sw.js</code>）中引入</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">importScripts(<span class="string">&quot;https://cdn.webpushr.com/sw-server.min.js&quot;</span>);</span><br></pre></td></tr></table></figure><p>完成这些你就可以自行注册你的<code>sw</code>脚本了，如果你需要了解如何编写或注册<code>service worker</code>脚本，可以参考以下文章或项目 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://kmar.top/posts/73014407/">hexo-swpp</a><br><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.cyfan.top/p/c0af86bb.html">Service Worker</a><br><a target="_blank" rel="noopener external nofollow noreferrer" href="https://clientworker.js.org/">clientworker</a><br><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/GoogleChrome/workbox">Workbox</a></p><h2 id="自定义">自定义<a class="fa-solid fa-hashtag" href="#自定义"></a></h2><p>个人建议将控制台右上角小铃铛 🔔 里全部配置一遍以获得更好的效果</p><p>你需要自定义一些参数才可以使用根据不同主题，按照订阅者订阅话题推送功能（目前根据个人需求是这个设置，默认行为为当未匹配到对应分类时不推送文章，而不是向所有用户推送文章，当然你也可以配置目标为所有用户）</p><p>在控制台，点击<code>Setup</code>&gt;<code>Opt-In Prompt</code> ，向下滑动打开<code>Enable Topics</code>（小铃铛样式无此选项，因此推荐您使用前两种样式），并新增几个主题，对应你想推送的文章分类即可</p><p>然后点击<code>Users</code>&gt;<code>Segments</code> ，即可获取对应的<code>segment</code>关系，依次填入配置项即可</p><h2 id="工作原理">工作原理<a class="fa-solid fa-hashtag" href="#工作原理"></a></h2><p>当你运行<code>hexo generate</code>插件会在<code>public</code> 目录生成 <code>newPost.json</code> 这样一个文件. <code>newPost.json</code> 包含了一些你想推送的新文章相关信息，示例格式如下</p><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;title&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Hexo浏览器定向推送文章更新&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;updated&quot;</span><span class="punctuation">:</span> <span class="string">&quot;2023-04-22T20:25:00+08:00&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;message&quot;</span><span class="punctuation">:</span> <span class="string">&quot;这一次，CC的部落格可以根据读者订阅主题定向推送了，并且实现了NPM插件化&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;target_url&quot;</span><span class="punctuation">:</span> <span class="string">&quot;https://blog.ccknbc.cc/posts/hexo-webpushr-notification/&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;image&quot;</span><span class="punctuation">:</span> <span class="string">&quot;https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/d2a947d48815ed24936a919873b97841_w1366_h768_s31.png&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;categories&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;博客&quot;</span><span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;schedule&quot;</span><span class="punctuation">:</span> <span class="string">&quot;2023-06-13T15:16:41.187Z&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;expire&quot;</span><span class="punctuation">:</span> <span class="string">&quot;7d&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;auto_hide&quot;</span><span class="punctuation">:</span> <span class="string">&quot;1&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure><p>而他的来源就是我们在文章开头<code>Front-Matter</code>自定义的那些属性，而本插件针对<code>Butterfly</code>主题做了针对性修改，您也可以在您的模板文件目录下修改文章模板文件(<code>Hexo/scaffolds/post.md</code>)，主要针对性参数如下</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">date:</span></span><br><span class="line"><span class="attr">updated:</span></span><br><span class="line"><span class="attr">schedule:</span> <span class="string">对应配置项中定时推送时间</span></span><br><span class="line"><span class="attr">auto_hide:</span> <span class="string">对应配置项中是否自动隐藏</span></span><br><span class="line"><span class="attr">expire:</span> <span class="string">对应配置项中过期时间</span></span><br><span class="line"><span class="attr">categories:</span> <span class="string">文章分类</span></span><br><span class="line"><span class="attr">description:</span> <span class="string">对应配置项中message，即文章描述</span></span><br><span class="line"><span class="attr">cover:</span> <span class="string">对应配置项中image，默认选取文章封面</span></span><br></pre></td></tr></table></figure><p>如果你的主题不是采用默认的<code>date</code> <code>updated</code> 参数，记得补充，因为这是判断最新文章的依据</p><p>如果你习惯了使用截断的方式，也无需配置<code>description</code>继续使用，示例如下，注意<code>&lt;!-- more --&gt;</code></p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: Hexo使用Web Push Notification 浏览器通知推送</span><br><span class="line">tags:</span><br><span class="line"><span class="bullet">  -</span> hexo</span><br><span class="line"><span class="bullet">  -</span> 服务器推送技术</span><br><span class="line"><span class="bullet">  -</span> push notifications</span><br><span class="line">categories:</span><br><span class="line"><span class="bullet">  -</span> 开发</span><br><span class="line">comments: true</span><br><span class="line">abbrlink: 98ae9e55</span><br><span class="line"><span class="section">date: 2020-02-26 10:00:00</span></span><br><span class="line"><span class="section">---</span></span><br><span class="line"></span><br><span class="line">Web Push Notification 是怎么工作的？个人博客为什么要使用它？如何使用它？</span><br><span class="line"></span><br><span class="line">&lt;!-- more --&gt;</span><br></pre></td></tr></table></figure><p>当执行 <code>hexo deploy</code>命令时，插件会比较在线版本和本地版本<code>newPost.json</code>中最新文章更新时间是否一致，如果不同，则插件将推送最新文章更新通知（默认为十分钟后推送）</p><p><strong>注意</strong>：如果您是第一次使用本地测试应该看到</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">INFO  无文章更新 或 为首次推送更新</span><br></pre></td></tr></table></figure><p>这是正常现象，因为此时你的网站还没有<code>newPost.json</code>这个文件，后续有更新时将正常推送，你可以先推送一次，再修改更新时间测试一次，当然建议测试目标选择自己，即 sid 选项配置</p><p>当然如果您在使用过程中有什么问题或遇到了 Bug 也欢迎随时在评论区或<a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/Rock-Candy-Tea/hexo-webpushr-notification/issues">issues</a>反馈，当然因为本人是菜鸡，所以有大佬 PR 最好了</p><h2 id="推送效果">推送效果<a class="fa-solid fa-hashtag" href="#推送效果"></a></h2><p>因为我是通知自动隐藏后才截图，所以大致效果如下所示 <img src= "" data-lazy-src="https://cdn.nlark.com/yuque/0/2022/png/8391407/1664951686275-f37cb76d-34f6-40ed-94c6-9bed130d0605.png#averageHue=%23bec0b3&amp;clientId=ub7fa2e19-f596-4&amp;errorMessage=unknown%20error&amp;from=paste&amp;height=402&amp;id=u898a4c3c&amp;originHeight=502&amp;originWidth=412&amp;originalType=binary&amp;ratio=1&amp;rotation=0&amp;showTitle=false&amp;size=165943&amp;status=error&amp;style=none&amp;taskId=u3d6496ee-c850-4052-978a-8c49a9055ca&amp;title=&amp;width=329.6" alt="image.png" loading="lazy"></p><h2 id="后续计划">后续计划<a class="fa-solid fa-hashtag" href="#后续计划"></a></h2><ul class="contains-task-list"><li class="task-list-item"><input class="task-list-item-checkbox" checked disabled type="checkbox"> 兼容自定义<code>Service Work</code>的功能，因为<code>webpushr-sw.js</code>优先注册的原因，只能有一个 <code>sw</code>注册，无法注册自己编写脚本。</li><li class="task-list-item"><input class="task-list-item-checkbox" checked disabled type="checkbox"> 支持参数更多的可自定义，启用或关闭。例如不延时，立即发送；不显示按钮（因为默认就是跳转到文章）等</li><li class="task-list-item"><input class="task-list-item-checkbox" checked disabled type="checkbox"> 目前的判断逻辑，虽然可以根据更新时间来判断，但如果很久之前的文章翻新，只要更新时间最新，也会触发推送，主要针对 updated 方式，还没想到好的解决办法，目前就是确认需要推送才更改更新时间咯</li><li class="task-list-item"><input class="task-list-item-checkbox" disabled type="checkbox"> 优化代码，减少代码量</li></ul></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://blog.ccknbc.cc/">CC康纳百川</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://blog.ccknbc.cc/posts/hexo-webpushr-notification/">https://blog.ccknbc.cc/posts/hexo-webpushr-notification/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/"><i style="color:#8fbc8f" class="fa-brands fa-creative-commons"></i> <i style="color:#8fbc8f" class="fa-brands fa-creative-commons-by"></i> <i style="color:#8fbc8f" class="fa-brands fa-creative-commons-nc"></i> <i style="color:#8fbc8f" class="fa-brands fa-creative-commons-sa"></i> CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://blog.ccknbc.cc">CC的部落格</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E5%8D%9A%E5%AE%A2/">博客</a><a class="post-meta__tags" href="/tags/%E5%B7%A5%E5%85%B7/">工具</a></div><div class="post_share"><div class="social-share" data-image="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/d2a947d48815ed24936a919873b97841_w1366_h768_s31.png" data-sites="wechat,weibo,qq,facebook,twitter"></div><link rel="stylesheet" href="https://jsd.cdn.zzko.cn/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload='this.media="all"'><script src="https://jsd.cdn.zzko.cn/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i>赞赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://www.rocschool.com/tool/qr/qr/id/51.html" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="https://jsd.cdn.zzko.cn/gh/ccknbc-backup/cdn/logo/qr.png" alt="三合一"></a><div class="post-qr-code-desc">三合一</div></li><li class="reward-item"><a href="https://afdian.net/@ccknbc" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="https://jsd.cdn.zzko.cn/gh/ccknbc-backup/cdn/logo/afdian.png" alt="爱发电"></a><div class="post-qr-code-desc">爱发电</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/yuque-to-hexo/" title="语雀文章同步至Hexo笔记"><img class="cover" src= "" data-lazy-src="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/721e476cb2661152b9c43621c94e3ed7_w1366_h768_s86.png" onerror='onerror=null,src="https://jsd.cdn.zzko.cn/npm/hexo-theme-anzhiyu/source/img/friend_404.gif"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">语雀文章同步至Hexo笔记</div></div></a></div><div class="next-post pull-right"><a href="/posts/song-about-you-live-in-the-sky-2023/" title="2023《好好》线上演唱会"><img class="cover" src= "" data-lazy-src="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/fd4ab8b7ef7189003bfa3857a9a451ab_w1280_h720_s185.jpg" onerror='onerror=null,src="https://jsd.cdn.zzko.cn/npm/hexo-theme-anzhiyu/source/img/friend_404.gif"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">2023《好好》线上演唱会</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/yuque-to-hexo/" title="语雀文章同步至Hexo笔记"><img class="cover" src= "" data-lazy-src="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/721e476cb2661152b9c43621c94e3ed7_w1366_h768_s86.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-10-04</div><div class="title">语雀文章同步至Hexo笔记</div></div></a></div><div><a href="/posts/how-to-hide-hexo-articles-gracefully/" title="如何优雅隐藏 Hexo 文章"><img class="cover" src= "" data-lazy-src="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/aa5ebc0731a66fa5fb73df76da759ae3_w1920_h1080_s557.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-22</div><div class="title">如何优雅隐藏 Hexo 文章</div></div></a></div><div><a href="/posts/google-adsense-configuration-manual/" title="Google Adsense 配置手册"><img class="cover" src= "" data-lazy-src="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/0a77436f677dd11422579e07ba6423b3_w1920_h1080_s188.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-24</div><div class="title">Google Adsense 配置手册</div></div></a></div><div><a href="/posts/introduction-of-plugin-tags-based-on-butterfly/" title="Hexo标签笔记"><img class="cover" src= "" data-lazy-src="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/666ccfeb387717d69a0e3333cc1170dc_w1004_h591_s48.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-05</div><div class="title">Hexo标签笔记</div></div></a></div><div><a href="/posts/the-webp-road-of-blog-pictures/" title="博客图片的 WebP 之路"><img class="cover" src= "" data-lazy-src="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/a4d78fbe1ca6e99e19535a095681c5ba_w1920_h1080_s770.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-11-29</div><div class="title">博客图片的 WebP 之路</div></div></a></div><div><a href="/posts/hexo-toss/" title="HEXO 折腾"><img class="cover" src= "" data-lazy-src="https://pic1.afdiancdn.com/user/8a7f563c2e3811ecab5852540025c377/common/45d888bd81b86777b3364e4a16ff72c6_w2240_h1260_s476.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-07-01</div><div class="title">HEXO 折腾</div></div></a></div></div></div><hr class="custom-hr"><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="waline-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85"><span class="toc-number">1.</span> <span class="toc-text">安装</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BF%AE%E6%94%B9"><span class="toc-number">1.1.</span> <span class="toc-text">自定义修改</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8"><span class="toc-number">2.</span> <span class="toc-text">使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A2%9D%E5%A4%96%E9%85%8D%E7%BD%AE"><span class="toc-number">3.</span> <span class="toc-text">额外配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89"><span class="toc-number">4.</span> <span class="toc-text">自定义</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86"><span class="toc-number">5.</span> <span class="toc-text">工作原理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A8%E9%80%81%E6%95%88%E6%9E%9C"><span class="toc-number">6.</span> <span class="toc-text">推送效果</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%90%8E%E7%BB%AD%E8%AE%A1%E5%88%92"><span class="toc-number">7.</span> <span class="toc-text">后续计划</span></a></li></ol></div></div></div></div></main><footer id="footer" style="background:linear-gradient(135deg,#fff1eb,#ace0f9)"><div id="footer-wrap"><div class="icp"><a target="_blank" rel="noopener external nofollow noreferrer" href="https://beian.miit.gov.cn"><img class="icp-icon" src= "" data-lazy-src="https://jsd.cdn.zzko.cn/gh/ccknbc-backup/cdn/logo/icp.png" alt="ICP"><span>鄂 ICP 备 2020019764 号</span></a></div><div class="gongan"><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=42088102000092"><img class="gongan-icon" src= "" data-lazy-src="https://jsd.cdn.zzko.cn/gh/ccknbc-backup/cdn/logo/gongan.png" alt="gongan"><span>鄂公网安备 42088102000092 号</span></a></div><div class="live"><span>本站已运行</span><span id="display_live"></span><span class="moe-text">CCKNBC All Rights Reserved.</span><script>function blog_live(){window.setTimeout(blog_live,1e3);var e=new Date("2020-06-04T00:00:00"),o=new Date,l=o.getFullYear(),o=o.getTime()-e.getTime(),e=864e5,t=365*e,i=Math.floor(o/t),t=Math.floor(o%t/e),e=Math.floor(o%e/60/60/1e3),a=Math.floor(o%36e5/60/1e3),o=Math.floor(o%6e4/1e3);display_live.innerHTML=" "+i+" 年 "+t+" 天 "+e+" 小时 "+a+" 分 "+o+" 秒<br>&copy; 2020 - "+l+" "}blog_live()</script></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><a class="edit-yuque" target="_blank" rel="noopener external nofollow noreferrer" href="https://www.yuque.com/ccknbc/blog/37/edit/" title="在语雀上以富文本格式编辑/预览 - Hexo浏览器定向推送文章更新"><i class="fa-solid fa-crow"></i></a><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fa-solid fa-arrows-alt-h"></i></button><button id="readmode" type="button" title="阅读模式"><i class="fa-solid fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fa-solid fa-adjust"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fa-solid fa-cog"></i></button><button id="share-link" type="button" title="分享链接"><i class="fa-solid fa-share"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fa-solid fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fa-solid fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fa-solid fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://jsd.cdn.zzko.cn/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.js"></script><script src="https://jsd.cdn.zzko.cn/npm/instant.page/instantpage.js" type="module"></script><script src="https://jsd.cdn.zzko.cn/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://jsd.cdn.zzko.cn/npm/node-snackbar/dist/snackbar.min.js"></script><div class="js-pjax"><script>(()=>{var e=()=>{var e;const t=document.querySelectorAll("#article-container .mermaid-wrap");0!==t.length&&(e=()=>{{var e=t;window.loadMermaid=!0;const a="dark"===document.documentElement.getAttribute("data-theme")?"dark":"default";Array.from(e).forEach((e,t)=>{const n=e.firstElementChild;e="%%{init:{ 'theme':'"+a+"'}}%%\n"+n.textContent;const d=mermaid.render("mermaid-"+t,e);"string"==typeof d?(t=d,n.insertAdjacentHTML("afterend",t)):d.then(({svg:e})=>{n.insertAdjacentHTML("afterend",e)})})}},btf.addGlobalFn("themeChange",e,"mermaid"),window.loadMermaid?e():btf.getScript("https://jsd.cdn.zzko.cn/npm/mermaid/dist/mermaid.min.js").then(e))};btf.addGlobalFn("encrypt",e,"mermaid"),window.pjax?e():document.addEventListener("DOMContentLoaded",e)})()</script><script>(()=>{let n=window.walineFn||null;const t=e=>{const n=e(Object.assign({el:"#waline-wrap",serverURL:"https://waline.ccknbc.cc",pageview:!1,dark:'html[data-theme="dark"]',path:window.location.pathname,comment:!1,imageUploader:function(e){var n=new FormData,t=new Headers;return n.append("file",e),n.append("album_id","10"),n.append("permission","0"),t.append("Authorization","Bearer 24|o8Crl5y0oK3luyUs17fBxDtAcevk1iiLHVFMNjpA"),t.append("Accept","application/json"),fetch("https://wmimg.com/api/v1/upload",{method:"POST",headers:t,body:n}).then(e=>e.json()).then(e=>e.data.links.url)}},{pageSize:10,meta:["nick","mail","link"],requiredMeta:["nick","mail"],login:"force",copyright:!0,search:!0,turnstileKey:"0x4AAAAAAAECBl27OB5SZrQT",locale:{admin:"博主",sofa:"这里冷冷清清的，快来留下脚印吧！",placeholder:"根据《互联网跟帖评论服务管理规定》，将展示您的归属地，并开启强制注册登录后才允许评论\n社交登录现已支持【QQ Weibo GitHub X Facebook】等平台，登录后可点击头像更改个人主页地址，方便CC串门\n在评论框粘贴图片，自动上传至图床，请不要将评论区作为您的图床，更不要上传违法图片，谢谢合作",reactionTitle:"就现在，表明你的态度！",reaction0:"鼓励",reaction1:"菜狗",reaction2:"正确",reaction3:"错误",reaction4:"思考",reaction5:"无聊",level0:"买菜",level1:"切菜",level2:"炒菜",level3:"煲汤",level4:"煮面",level5:"上桌",level6:"开吃"},emoji:["https://jsd.cdn.zzko.cn/npm/sticker-heo/Sticker-100/"],reaction:["https://jsd.cdn.zzko.cn/npm/sticker-heo/Sticker-100/鼓掌.png","https://jsd.cdn.zzko.cn/npm/sticker-heo/Sticker-100/菜狗.png","https://jsd.cdn.zzko.cn/npm/sticker-heo/Sticker-100/正确.png","https://jsd.cdn.zzko.cn/npm/sticker-heo/Sticker-100/错误.png","https://jsd.cdn.zzko.cn/npm/sticker-heo/Sticker-100/思考.png","https://jsd.cdn.zzko.cn/npm/sticker-heo/Sticker-100/睡觉.png"]}));btf.addGlobalFn("pjax",()=>{n.destroy()},"destroyWaline")};var e=()=>{n?t(n):(btf.getCSS("https://jsd.cdn.zzko.cn/npm/@waline/client/dist/waline.css"),btf.getCSS("https://jsd.cdn.zzko.cn/npm/@waline/client/dist/waline-meta.css").then(()=>import("https://jsd.cdn.zzko.cn/npm/@waline/client/dist/waline.js")).then(({init:e})=>{n=e||Waline.init,t(n),window.walineFn=n}))};btf.loadComment(document.getElementById("waline-wrap"),e)})()</script></div><script>window.addEventListener("load",()=>{const t=e=>e=""!==e&&150<(e=(e=(e=(e=e.replace(/<img.*?src="(.*?)"?[^\>]+>/gi,"[图片]")).replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi,"[链接]")).replace(/<pre><code>.*?<\/pre>/gi,"[代码]")).replace(/<[^>]+>/g,"")).length?e.substring(0,150)+"...":e,a=t=>{let a="";if(t.length)for(let e=0;e<t.length;e++)a=(a+="<div class='aside-list-item'>")+`<div class='content'>
        <a class='comment' href='${t[e].url}' title='${t[e].content}'>${t[e].content}</a>
        <div class='name'><span>${t[e].nick} / </span><time datetime="${t[e].date}">${btf.diffDate(t[e].date,!0)}</time></div>
        </div></div>`;else a+="没有评论";var e=document.querySelector("#card-newest-comments .aside-list");e&&(e.innerHTML=a),window.lazyLoadInstance&&window.lazyLoadInstance.update(),window.pjax&&window.pjax.refresh(e)};var e=()=>{var e;document.querySelector("#card-newest-comments .aside-list")&&((e=btf.saveToLocal.get("waline-newest-comments"))?a(JSON.parse(e)):(async()=>{try{var e=(await(await fetch("https://waline.ccknbc.cc/api/comment?type=recent&count=3",{method:"GET"})).json()).data.map(e=>({content:t(e.comment),avatar:e.avatar,nick:e.nick,url:e.url+"#post-comment",date:e.time||e.insertedAt}));btf.saveToLocal.set("waline-newest-comments",JSON.stringify(e),10/1440),a(e)}catch(e){console.error(e),document.querySelector("#card-newest-comments .aside-list").textContent="无法获取评论，请确认相关配置是否正确"}})())};e(),btf.addGlobalFn("pjaxComplete",e,"waline_newestComment")})</script><script defer src="/js/custom.js"></script><script src="https://jsd.cdn.zzko.cn/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors=["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"];var pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:pjaxSelectors,cacheBust:!1,analytics:!1,scrollRestoration:!1});const triggerPjaxFn=e=>{e&&Object.values(e).forEach(e=>{e()})};document.addEventListener("pjax:send",function(){btf.removeGlobalFnEvent("pjax"),btf.removeGlobalFnEvent("themeChange");var e=document.body.classList;e.contains("read-mode")&&e.remove("read-mode"),triggerPjaxFn(window.globalFn.pjaxSend)}),document.addEventListener("pjax:complete",()=>{document.querySelectorAll("script[data-pjax]").forEach(e=>{const t=document.createElement("script");var a=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach(e=>t.setAttribute(e.name,e.value)),t.appendChild(document.createTextNode(a)),e.parentNode.replaceChild(t,e)}),triggerPjaxFn(window.globalFn.pjaxComplete)}),document.addEventListener("pjax:error",e=>{404===e.request.status&&pjax.loadUrl("/404")})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div class="docsearch-wrap"><div id="docsearch" style="display:none"></div><link rel="stylesheet" href="https://jsd.cdn.zzko.cn/npm/@docsearch/css/dist/style.css"><script src="https://jsd.cdn.zzko.cn/npm/@docsearch/js/dist/umd/index.js"></script><script>(()=>{docsearch(Object.assign({appId:"97MUPN4DMC",apiKey:"a003a39f337f5186ec11f5f92bae62b3",indexName:"ccknbc",container:"#docsearch"},{placeholder:"Ctrl/⌘ + K 唤醒搜索服务",maxResultsPerGroup:7,translations:{button:{buttonText:"搜索",buttonAriaLabel:"搜索"},modal:{searchBox:{resetButtonTitle:"清空",resetButtonAriaLabel:"清空",cancelButtonText:"取消",cancelButtonAriaLabel:"取消"},startScreen:{recentSearchesTitle:"最近搜索历史",noRecentSearchesText:"搜索历史为空",saveRecentSearchButtonTitle:"保存搜索记录",removeRecentSearchButtonTitle:"清除搜索记录",favoriteSearchesTitle:"收藏夹",removeFavoriteSearchButtonTitle:"移出收藏夹"},errorScreen:{titleText:"未能获取搜索结果",helpText:"您可能需要检查您的网络连接"},footer:{selectText:"选择",selectKeyAriaLabel:"回车键",navigateText:"切换",navigateUpKeyAriaLabel:"方向键上",navigateDownKeyAriaLabel:"方向键下",closeText:"关闭",closeKeyAriaLabel:"退出键",searchByText:"搜索服务提供: DocSearch by"},noResultsScreen:{noResultsText:"未搜索到相关内容",suggestedQueryText:"您可尝试搜索",reportMissingResultsText:"确认搜索结果是正确的？",reportMissingResultsLinkText:"反馈给Algolia"}}}}));const e=()=>{document.querySelector(".DocSearch-Button").click()};var t=()=>{btf.addEventListenerPjax(document.querySelector("#search-button > .search"),"click",e)};t(),window.addEventListener("pjax:complete",t)})()</script></div></div><script>const copyright_enable=!0</script><script src="https://jsd.cdn.zzko.cn/npm/turndown/dist/turndown.min.js"></script><script src="https://jsd.cdn.zzko.cn/gh/ccknbc-forked/hexo-butterfly-copymarkdown/lib/copyMarkdown.min.js"></script><script src="https://jsd.cdn.zzko.cn/gh/ccknbc-forked/hexo-butterfly-copymarkdown/lib/reprint.min.js"></script><script>(function (w, d, s, id) {
        if (typeof (w.webpushr) !== 'undefined') return;
        w.webpushr = w.webpushr || function () { (w.webpushr.q = w.webpushr.q || []).push(arguments) };
        var js, fjs = d.getElementsByTagName(s)[0];
        js = d.createElement(s);
        js.id = id;
        js.async = 1;
        js.src = "https://cdn.webpushr.com/app.min.js";
        fjs.parentNode.appendChild(js);
        }(window, document, 'script', 'webpushr-jssdk'));

        webpushr('setup', {
        'key': 'BB9Y-w9p3u0CKA7UP9nupB6I-_NqE2MuODmKJjyC4W2YflX06Ff_hEhrNJfonrut5l6gCa28gC83q2OII7Qv-oA',
        'sw': 'none'
        });
        </script></body></html>